package com.mf.service.impl.code;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.mf.config.GlobalParameter;
import com.mf.dto.MACD.MACDDto;
import com.mf.entity.Code;
import com.mf.entity.DayErrorCode;
import com.mf.entity.RecommendCode;
import com.mf.entity.code.*;
import com.mf.mapper.code.*;
import com.mf.service.IPositionsService;
import com.mf.service.code.ICodeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.utils.JsonParser;
import com.mf.vo.publicVo.DateScoped;
import jakarta.annotation.Resource;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mf
 * @since 2024-04-30
 */
@Service
public class CodeServiceImpl extends ServiceImpl<CodeMapper, Code> implements ICodeService {
    @Resource
    private Code000Mapper code000Mapper;

    @Resource
    private Code001Mapper code001Mapper;

    @Resource
    private Code002AMapper code002AMapper;

    @Resource
    private Code002BMapper code002BMapper;
    @Resource
    private  Code003Mapper code003Mapper;
    @Resource
    private Code300AMapper code300AMapper;
    @Resource
    private Code300BMapper code300BMapper;
    @Resource
    private Code301Mapper code301Mapper;
    @Resource
    private Code600AMapper code600AMapper;
    @Resource
    private Code600BMapper code600BMapper;
    @Resource
    private Code601Mapper code601Mapper;
    @Resource
    private Code603Mapper code603Mapper;
    @Resource
    private Code605Mapper code605Mapper;
    @Resource
    private Code688Mapper code688Mapper;
    @Resource
    private Code689Mapper code689Mapper;
    @Resource
    private DayErrorCodeMapper dayErrorCodeMapper;
    @Resource
    private IPositionsService positionsService;


    String todayAsString = LocalDate.now().format(GlobalParameter.FORMATTER2);
    // 获取3个月前的日期
    String oneAndHalfMonthAgo = LocalDate.now().minusMonths(1).format(GlobalParameter.FORMATTER2);

    @Override
    public List<RecommendCode> findNewChart(DateScoped dateScoped) {
        // 将查询时间在指定的时间前移动3个月(后续好让所有的指标有参考值)
        final LocalDate originalDate = LocalDate.parse(dateScoped.getStart(), GlobalParameter.FORMATTER2);
        final LocalDate localDate = originalDate.minusMonths(3);
        final String start = localDate.format(GlobalParameter.FORMATTER2);
        // 获取查询到的股票代码数据
        Map<String, Object> objectMap = positionsService.selectCode(dateScoped.getDm(), start,
                dateScoped.getEnd());
        System.out.println(objectMap+"objectMap");
        List<RecommendCode> recommendCodes = new ArrayList<>();
        Object data = objectMap.get("data");
        if(data instanceof Collection<?> dataCollection){
            for (Object item : dataCollection) {
                RecommendCode recommendCode = new RecommendCode();
                try {
                    BeanUtils.copyProperties(recommendCode, item);
                } catch (IllegalAccessException | InvocationTargetException e) {
                    throw new RuntimeException(e);
                }
                recommendCodes.add(recommendCode);
            }
        }
        return recommendCodes;
    }

    /**
     * 获取股票代码
     */
    @Override
    public List<Code> getCode() {
        // 假设HttpUtil.get返回一个字符串数组
        String jsonString = HttpUtil.get(GlobalParameter.HSLT + GlobalParameter.LICENCE);
        JSONArray jsonArray = new JSONArray(jsonString);
        List<Code> listCode = new ArrayList<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            // 将Object转换为JSONObject以访问其内部的键值对
            final JSONObject obj = jsonArray.getJSONObject(i);
            Code code = new Code();
            code.setDm(obj.getStr("dm"));
            code.setMc(obj.getStr("mc"));
            code.setJys(obj.getStr("jys"));
            listCode.add(code);
        }
        return  listCode;
    }

    /**
     * 获取历史数据
     */
    @Override
    public List<RecommendCode> findHistoricalData(MACDDto macdDto) {
        // 转换时间格式
        String url = GlobalParameter.HSZBL+macdDto.getDm()+"/"+macdDto.getType() + "/"+GlobalParameter.LICENCE;
        String jsonString = HttpUtil.get(url);
        List<RecommendCode> codeList = new ArrayList<>();
        if(jsonString.isEmpty() || "null".equals(jsonString) ){
            return codeList;
        }
        JSONArray jsonArray = new JSONArray(jsonString);
        for (int i = 0; i < jsonArray.size(); i++) {

            // 将Object转换为JSONObject以访问其内部的键值对
            final JSONObject obj = jsonArray.getJSONObject(i);
//            if(obj.getStr("d").contains("2024")){
            RecommendCode recommendCode = new RecommendCode();
            recommendCode.setDm(macdDto.getDm());
            recommendCode.setD(obj.getStr("d"));
            recommendCode.setC(Double.parseDouble(obj.getStr("c")));
            recommendCode.setO(Double.parseDouble(obj.getStr("o")));
            recommendCode.setH(Double.parseDouble(obj.getStr("h")));
            recommendCode.setL(Double.parseDouble(obj.getStr("l")));
            recommendCode.setV(Double.parseDouble(obj.getStr("v")));
            recommendCode.setE(Double.parseDouble(obj.getStr("e")));
            recommendCode.setZf(Double.parseDouble(obj.getStr("zf")));
            recommendCode.setHs(Double.parseDouble(obj.getStr("hs")));
            recommendCode.setZd(Double.parseDouble(obj.getStr("zd")));
            recommendCode.setZde(Double.parseDouble(obj.getStr("zde")));
            codeList.add(recommendCode);
//            }
        }
        return codeList;
    }


    public <T> String  getHttData(String dm,int count) {
        try {
            Thread.sleep(550);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        count--;
        System.out.println(dm+"获取中"+count);
        String url = GlobalParameter.HSZBL_NEW +dm+"/"+"dn/"+ GlobalParameter.LICENCE;
        return HttpUtil.get(url);
    }

    public  void saveErrorCode(String errorCode) {
        DayErrorCode dayErrorCode = new DayErrorCode();
        dayErrorCode.setErrorCode(errorCode);
        dayErrorCodeMapper.insert(dayErrorCode);
    }
    @Override
    public List<Code000> addNewestCode000() {
        List<Code000> list = new ArrayList<>();
        final List<Code000> code000s = code000Mapper.selectList(null);

        Set<String> uniqueDmSet = code000s.stream()
                // 提取dm字段
                .map(Code000::getDm)
                // 去重
                .collect(Collectors.toSet());

        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = code000s.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code000::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        System.out.println(idsToDelete.toString()+"要删除的数据集合");
//        if(!idsToDelete.isEmpty()){
////            code000Mapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code000 code000C = JsonParser.parseJsonToObject(Code000.class, httData, dm);
                list.add(code000C);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }
    @Override
    public List<Code001> addNewestCode001() {
        List<Code001> list = new ArrayList<>();
        final List<Code001> code000s = code001Mapper.selectList(null);
        Set<String> uniqueDmSet = code000s.stream()
                // 提取dm字段
                .map(Code001::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = code000s.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code001::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
////        if(!idsToDelete.isEmpty()){
////            code001Mapper.deleteBatchIds(idsToDelete);
////        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code001 code000C = JsonParser.parseJsonToObject(Code001.class, httData, dm);
                list.add(code000C);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code002A> addNewestCode002A() {
        List<Code002A> list = new ArrayList<>();
        final List<Code002A> codes = code002AMapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code002A::getDm)
                // 去重
                .collect(Collectors.toSet());

        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code002A::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code002AMapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code002A code = JsonParser.parseJsonToObject(Code002A.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code002B> addNewestCode002B() {
        List<Code002B> list = new ArrayList<>();
        final List<Code002B> codes = code002BMapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code002B::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code002B::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code002BMapper.deleteBatchIds(idsToDelete);
//        }
        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code002B code = JsonParser.parseJsonToObject(Code002B.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code003> addNewestCode003() {
        List<Code003> list = new ArrayList<>();
        final List<Code003> codes = code003Mapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code003::getDm)
                // 去重
                .collect(Collectors.toSet());

        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code003::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code003Mapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code003 code = JsonParser.parseJsonToObject(Code003.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code300A> addNewestCode300A() {
        List<Code300A> list = new ArrayList<>();
        final List<Code300A> codes = code300AMapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code300A::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code300A::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code300AMapper.deleteBatchIds(idsToDelete);
//        }
        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code300A code = JsonParser.parseJsonToObject(Code300A.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code300B> addNewestCode300B() {
        List<Code300B> list = new ArrayList<>();
        final List<Code300B> codes = code300BMapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code300B::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code300B::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code300BMapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code300B code = JsonParser.parseJsonToObject(Code300B.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code301> addNewestCode301() {
        List<Code301> list = new ArrayList<>();
        final List<Code301> codes = code301Mapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code301::getDm)
                // 去重
                .collect(Collectors.toSet());

        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code301::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code301Mapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code301 code = JsonParser.parseJsonToObject(Code301.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code600A> addNewestCode600A() {
        List<Code600A> list = new ArrayList<>();
        final List<Code600A> codes = code600AMapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code600A::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code600A::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code600AMapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code600A code = JsonParser.parseJsonToObject(Code600A.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code600B> addNewestCode600B() {
        List<Code600B> list = new ArrayList<>();
        final List<Code600B> codes = code600BMapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code600B::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code600B::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code600BMapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code600B code = JsonParser.parseJsonToObject(Code600B.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code601> addNewestCode601() {
        List<Code601> list = new ArrayList<>();
        final List<Code601> codes = code601Mapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code601::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code601::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code601Mapper.deleteBatchIds(idsToDelete);
//        }
        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code601 code = JsonParser.parseJsonToObject(Code601.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code603> addNewestCode603() {
        List<Code603> list = new ArrayList<>();
        final List<Code603> codes = code603Mapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code603::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code603::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code603Mapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code603 code = JsonParser.parseJsonToObject(Code603.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code605> addNewestCode605() {
        List<Code605> list = new ArrayList<>();
        final List<Code605> codes = code605Mapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code605::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code605::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code605Mapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code605 code = JsonParser.parseJsonToObject(Code605.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code688> addNewestCode688() {
        List<Code688> list = new ArrayList<>();
        final List<Code688> codes = code688Mapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code688::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code688::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code688Mapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code688 code = JsonParser.parseJsonToObject(Code688.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

    @Override
    public List<Code689> addNewestCode689() {
        List<Code689> list = new ArrayList<>();
        final List<Code689> codes = code689Mapper.selectList(null);
        Set<String> uniqueDmSet = codes.stream()
                // 提取dm字段
                .map(Code689::getDm)
                // 去重
                .collect(Collectors.toSet());

//        // 收集d字段日期为今天的记录的ID
//        List<Integer> idsToDelete = codes.stream()
//                // 筛选d字段日期为今天的记录和1.5个月前的记录
//                .filter(code000 -> code000.getD().equals(todayAsString) || code000.getD().equals(oneAndHalfMonthAgo))
//                // 提取ID
//                .map(Code689::getId)
//                // 收集ID
//                .toList();
//        // 删除当天数据
//        if(!idsToDelete.isEmpty()) {
//            code689Mapper.deleteBatchIds(idsToDelete);
//        }

        int count = uniqueDmSet.size();
        for (String dm : uniqueDmSet) {
            count--;
            String httData = getHttData(dm, count);
            if(!"null".equals(httData)){
                Code689 code = JsonParser.parseJsonToObject(Code689.class, httData, dm);
                list.add(code);
            }else{
                saveErrorCode(dm);
            }
        }
        return list;
    }

}
